package com.lm.memcached.config;

import net.spy.memcached.MemcachedClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.net.InetSocketAddress;

@Configuration
public class MemcachedConfig {

    @Value("${memcached.servers}")
    private String servers;

    @Bean
    public MemcachedClient memcachedClient() throws IOException {
        // 默认连接到 localhost:11211
        String[] server = servers.split(":");
        return new MemcachedClient(new InetSocketAddress(server[0], Integer.parseInt(server[1])));
    }
}